<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Dart基础 | Element</title><meta name="keywords" content="Dart"><meta name="author" content="FHang"><meta name="copyright" content="FHang"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><meta name="description" content="Dart1. Dart 安装 配套Flutter使用，安装Flutter SDK 1.21之后的版本，默认包含了最新的Dart SDK，不需要再额外安装Dart SDK  运行命令 12PS C:\Windows\System32&gt; dart --versionDart SDK version: 2.12.3 (stable) (Wed Apr 14 11:02:39 2021 +0200)">
<meta property="og:type" content="article">
<meta property="og:title" content="Dart基础">
<meta property="og:url" content="https://fhangh.gitee.io/article/5888643d.html">
<meta property="og:site_name" content="Element">
<meta property="og:description" content="Dart1. Dart 安装 配套Flutter使用，安装Flutter SDK 1.21之后的版本，默认包含了最新的Dart SDK，不需要再额外安装Dart SDK  运行命令 12PS C:\Windows\System32&gt; dart --versionDart SDK version: 2.12.3 (stable) (Wed Apr 14 11:02:39 2021 +0200)">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/FHangH/FHangBlogCDN/Post_Img_mini/postImg_16.jpg">
<meta property="article:published_time" content="2021-04-21T08:44:39.900Z">
<meta property="article:modified_time" content="2021-04-22T07:34:00.078Z">
<meta property="article:author" content="FHang">
<meta property="article:tag" content="Dart">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/gh/FHangH/FHangBlogCDN/Post_Img_mini/postImg_16.jpg"><link rel="shortcut icon" href="/fhangh/img/fh.png"><link rel="canonical" href="https://fhangh.gitee.io/article/5888643d"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta name="yandex-verification" content="{&quot;theme_color&quot;:{&quot;enable&quot;:true,&quot;main&quot;:&quot;#49B1F5&quot;,&quot;paginator&quot;:&quot;#00c4b6&quot;,&quot;button_hover&quot;:&quot;#FF7242&quot;,&quot;text_selection&quot;:&quot;#00c4b6&quot;,&quot;link_color&quot;:&quot;#99a9bf&quot;,&quot;meta_color&quot;:&quot;#858585&quot;,&quot;hr_color&quot;:&quot;#A4D8FA&quot;,&quot;code_foreground&quot;:&quot;#F47466&quot;,&quot;code_background&quot;:&quot;rgba(27, 31, 35, .05)&quot;,&quot;toc_color&quot;:&quot;#00c4b6&quot;,&quot;blockquote_padding_color&quot;:&quot;#49b1f5&quot;,&quot;blockquote_background_color&quot;:&quot;#49b1f5&quot;}}"/><link rel="stylesheet" href="/fhangh/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css"><script>var GLOBAL_CONFIG = { 
  root: '/fhangh/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  ClickShowText: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"top-right"},
  justifiedGallery: {
    js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
    css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isanchor: false
};

var saveToLocal = {
  set: function setWithExpiry(key, value, ttl) {
    const now = new Date()
    const expiryDay = ttl * 86400000
    const item = {
      value: value,
      expiry: now.getTime() + expiryDay,
    }
    localStorage.setItem(key, JSON.stringify(item))
  },

  get: function getWithExpiry(key) {
    const itemStr = localStorage.getItem(key)

    if (!itemStr) {
      return undefined
    }
    const item = JSON.parse(itemStr)
    const now = new Date()

    if (now.getTime() > item.expiry) {
      localStorage.removeItem(key)
      return undefined
    }
    return item.value
  }
}</script><script id="config_change">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-04-22 15:34:00'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(function () {  window.activateDarkMode = function () {
    document.documentElement.setAttribute('data-theme', 'dark')
    if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
    }
  }
  window.activateLightMode = function () {
    document.documentElement.setAttribute('data-theme', 'light')
   if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
    }
  }
  const autoChangeMode = 'false'
  const t = saveToLocal.get('theme')
  if (autoChangeMode === '1') {
    const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
    const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
    const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
    const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified
    if (t === undefined) {
      if (isLightMode) activateLightMode()
      else if (isDarkMode) activateDarkMode()
      else if (isNotSpecified || hasNoSupport) {
        const now = new Date()
        const hour = now.getHours()
        const isNight = hour <= 6 || hour >= 18
        isNight ? activateDarkMode() : activateLightMode()
      }
      window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
        if (saveToLocal.get('theme') === undefined) {
          e.matches ? activateDarkMode() : activateLightMode()
        }
      })
    } else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else if (autoChangeMode === '2') {
    const now = new Date()
    const hour = now.getHours()
    const isNight = hour <= 6 || hour >= 18
    if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
    else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else {
    if (t === 'dark') activateDarkMode()
    else if (t === 'light') activateLightMode()
  }const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
   if (asideStatus === 'hide') {
     document.documentElement.classList.add('hide-aside')
   } else {
     document.documentElement.classList.remove('hide-aside')
   }
}})()</script><meta name="generator" content="Hexo 5.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" data-lazy-src="/fhangh/img/fh.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/fhangh/archives/"><div class="headline">文章</div><div class="length-num">26</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/fhangh/tags/"><div class="headline">标签</div><div class="length-num">10</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/fhangh/categories/"><div class="headline">分类</div><div class="length-num">4</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/fhangh/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/fhangh/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/fhangh/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/fhangh/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/fhangh/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/fhangh/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 列表</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/fhangh/music/"><i class="fa-fw fas fa-music"></i><span> Music</span></a></li><li><a class="site-page" href="/fhangh/movies/"><i class="fa-fw fas fa-video"></i><span> Movie</span></a></li><li><a class="site-page" href="/fhangh/Gallery/"><i class="fa-fw fas fa-images"></i><span> Image</span></a></li></ul></div></div></div></div><div id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url(https://cdn.jsdelivr.net/gh/FHangH/FHangBlogCDN/Post_Img/postImg_16.jpg)"><nav id="nav"><span id="blog_name"><a id="site-name" href="/fhangh/">Element</a></span><span id="menus"><div id="search_button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/fhangh/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/fhangh/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/fhangh/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/fhangh/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/fhangh/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/fhangh/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 列表</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/fhangh/music/"><i class="fa-fw fas fa-music"></i><span> Music</span></a></li><li><a class="site-page" href="/fhangh/movies/"><i class="fa-fw fas fa-video"></i><span> Movie</span></a></li><li><a class="site-page" href="/fhangh/Gallery/"><i class="fa-fw fas fa-images"></i><span> Image</span></a></li></ul></div></div><span class="close" id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></span></span></nav><div id="post-info"><h1 class="post-title">Dart基础</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-04-21T08:44:39.900Z" title="发表于 2021-04-21 16:44:39">2021-04-21</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-04-22T07:34:00.078Z" title="更新于 2021-04-22 15:34:00">2021-04-22</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/fhangh/categories/%E7%BC%96%E7%A8%8B/">编程</a></span></div><div class="meta-secondline"> <span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.3k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>6分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="Dart"><a href="#Dart" class="headerlink" title="Dart"></a>Dart</h1><h3 id="1-Dart-安装"><a href="#1-Dart-安装" class="headerlink" title="1. Dart 安装"></a>1. Dart 安装</h3><ul>
<li><p>配套Flutter使用，安装Flutter SDK 1.21之后的版本，默认包含了最新的Dart SDK，不需要再额外安装Dart SDK</p>
</li>
<li><p>运行命令</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">PS</span> C:\Windows\System32&gt; dart -<span class="literal">-version</span></span><br><span class="line">Dart SDK version: <span class="number">2.12</span>.<span class="number">3</span> (stable) (Wed Apr <span class="number">14</span> <span class="number">11</span>:<span class="number">02</span>:<span class="number">39</span> <span class="number">2021</span> +<span class="number">0200</span>) on <span class="string">&quot;windows_x64&quot;</span></span><br></pre></td></tr></table></figure>




</li>
</ul>
<h3 id="2-Dart-环境配置"><a href="#2-Dart-环境配置" class="headerlink" title="2. Dart 环境配置"></a>2. Dart 环境配置</h3><ol>
<li>安装完Flutter之后，打开VSCode</li>
<li>在VSCode的扩展项里，搜索 Dart 和 Code Runner 安装即可</li>
</ol>
<h3 id="3-Dart-项目文件"><a href="#3-Dart-项目文件" class="headerlink" title="3. Dart 项目文件"></a>3. Dart 项目文件</h3><ol>
<li><p>打开VSCode，Ctrl + N，新建文件</p>
</li>
<li><p>Ctrl + S，另存为，修改文件后缀名 .dart，即可 (demo.dart)</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">void</span> main() &#123;</span><br><span class="line">  <span class="built_in">print</span>(<span class="string">&quot;Hello World !&quot;</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>Ctrl + Alt + N，运行即可看到打印结果</p>
<p>或者进入项目内：</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">dart demo1.dart</span><br><span class="line"></span><br><span class="line">// 实际效果</span><br><span class="line"><span class="built_in">PS</span> C:\Users\Admin\Desktop\dart_demo&gt; dart .\demo1.dart</span><br><span class="line">Hello World !</span><br></pre></td></tr></table></figure>




</li>
</ol>
<h3 id="5-Dart-基本语法"><a href="#5-Dart-基本语法" class="headerlink" title="5. Dart 基本语法"></a>5. Dart 基本语法</h3><h4 id="5-1-Dart-变量类型"><a href="#5-1-Dart-变量类型" class="headerlink" title="5.1 Dart 变量类型"></a>5.1 Dart 变量类型</h4><figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">void</span> main() &#123;</span><br><span class="line">  <span class="comment">// var 可以自动通过类型声明变量</span></span><br><span class="line">  <span class="keyword">var</span> str1 = <span class="string">&quot;Hello World 1&quot;</span>;</span><br><span class="line">  <span class="keyword">var</span> num1 = <span class="number">1111</span>;</span><br><span class="line">  <span class="built_in">print</span>(str1);</span><br><span class="line">  <span class="built_in">print</span>(num1);</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 常规的指定变量类型</span></span><br><span class="line">  <span class="built_in">String</span> str2 = <span class="string">&quot;Hello World 2&quot;</span>;</span><br><span class="line">  <span class="built_in">int</span> num2 = <span class="number">2222</span>;</span><br><span class="line">  <span class="built_in">print</span>(str2);</span><br><span class="line">  <span class="built_in">print</span>(num2);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>




<h4 id="5-2-Dart-常量"><a href="#5-2-Dart-常量" class="headerlink" title="5.2 Dart 常量"></a>5.2 Dart 常量</h4><ul>
<li><p>const 修饰，需要赋初值</p>
</li>
<li><p>final 修饰，可不赋初值，只能赋值一次</p>
</li>
<li><p>永远不改变的值，需要用 const 或 final 修饰，不可用 var 或 其他类型</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">void</span> main() &#123;</span><br><span class="line">  <span class="keyword">var</span> str = <span class="string">&quot;Hello World 01&quot;</span>;</span><br><span class="line">  str = <span class="string">&quot;Hello World 02&quot;</span>;</span><br><span class="line">  <span class="keyword">var</span> <span class="built_in">num</span> = <span class="number">1111</span>;  </span><br><span class="line">  <span class="built_in">num</span> = <span class="number">2222</span>;</span><br><span class="line">    </span><br><span class="line">  <span class="built_in">print</span>(str);</span><br><span class="line">  <span class="built_in">print</span>(<span class="built_in">num</span>);</span><br><span class="line"></span><br><span class="line">  <span class="keyword">const</span> str1 = <span class="string">&quot;Fang&quot;</span>;</span><br><span class="line">  <span class="keyword">const</span> num1 = <span class="number">2222</span>;</span><br><span class="line">  <span class="comment">// const 修饰后，再次赋值无效</span></span><br><span class="line">  str1 = <span class="string">&quot;Hang&quot;</span>;</span><br><span class="line">  num1 = <span class="number">1234</span>;</span><br><span class="line"></span><br><span class="line">  <span class="built_in">print</span>(str1);</span><br><span class="line">  <span class="built_in">print</span>(num1);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">#打印效果：显示错误#</span><br><span class="line">PS C:\Users\Admin&gt; dart <span class="string">&quot;c:\Users\Admin\Desktop\dart_demo\demo1.dart&quot;</span></span><br><span class="line">Desktop/dart_demo/demo1.dart:<span class="number">13</span>:<span class="number">3</span>: Error: Can<span class="string">&#x27;t assign to the const variable &#x27;</span>str1<span class="string">&#x27;.</span></span><br><span class="line"><span class="string">  str1 = &quot;Hang&quot;;</span></span><br><span class="line"><span class="string">  ^^^^</span></span><br><span class="line"><span class="string">Desktop/dart_demo/demo1.dart:14:3: Error: Can&#x27;</span>t assign to the <span class="keyword">const</span> variable <span class="string">&#x27;num1&#x27;</span>.</span><br><span class="line">  num1 = <span class="number">1234</span>;</span><br><span class="line">  ^^^^</span><br></pre></td></tr></table></figure></li>
<li><p>final 和 const 的区别：（final只有在在运行时才会赋值一次，而const必须提前赋值）</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">void</span> main() &#123;</span><br><span class="line">  <span class="keyword">final</span> f_timeNow = <span class="keyword">new</span> <span class="built_in">DateTime</span>.now();</span><br><span class="line">  <span class="built_in">print</span>(f_timeNow);</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 错误的用法</span></span><br><span class="line">  <span class="keyword">const</span> c_timeNow = <span class="keyword">new</span> <span class="built_in">DateTime</span>.now();</span><br><span class="line">  <span class="built_in">print</span>(c_timeNow);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">#打印效果：显示错误#</span><br><span class="line">PS C:\Users\Admin&gt; dart <span class="string">&quot;c:\Users\Admin\Desktop\dart_demo\demo1.dart&quot;</span></span><br><span class="line">Desktop/dart_demo/demo1.dart:<span class="number">5</span>:<span class="number">21</span>: Error: New expression <span class="keyword">is</span> not a constant expression.</span><br><span class="line">  <span class="keyword">const</span> c_timeNow = <span class="keyword">new</span> <span class="built_in">DateTime</span>.now();</span><br><span class="line">                    ^^^</span><br></pre></td></tr></table></figure>





</li>
</ul>
<h4 id="5-3-Dart-数据类型"><a href="#5-3-Dart-数据类型" class="headerlink" title="5.3 Dart 数据类型"></a>5.3 Dart 数据类型</h4><ul>
<li>常用的数据类型：<ol>
<li>Number（数值）<ul>
<li>int</li>
<li>double</li>
</ul>
</li>
<li>String（字符串）<ul>
<li>String</li>
</ul>
</li>
<li>Boolen（布尔）<ul>
<li>bool</li>
</ul>
</li>
<li>List（数组）<ul>
<li>在Dart中，数组是列表的对象，大部分情况下称之为列表</li>
</ul>
</li>
<li>Map（字典）<ul>
<li>Map是一个（键，值）对的对象，（键，值）可以是任何类型的对象</li>
</ul>
</li>
</ol>
</li>
<li>不常用的数据类型：<ol>
<li>Rune：Dart中UTF-32编码字符串，可以通过文字转换成符号表情或特定的字</li>
<li>Symbol：Dart程序中声明的运算符和标识符</li>
</ol>
</li>
</ul>
<h4 id="5-4-Dart-字符串"><a href="#5-4-Dart-字符串" class="headerlink" title="5.4 Dart 字符串"></a>5.4 Dart 字符串</h4><h5 id="5-4-1-Dart-字符串定义"><a href="#5-4-1-Dart-字符串定义" class="headerlink" title="5.4.1 Dart 字符串定义"></a>5.4.1 Dart 字符串定义</h5><ul>
<li><p>不换行（示例）：单引号 // 双引号</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">void</span> main() &#123;</span><br><span class="line">  <span class="keyword">var</span> str1 = <span class="string">&#x27;test string 01&#x27;</span>;</span><br><span class="line">  <span class="built_in">String</span> str2 = <span class="string">&quot;test string 02&quot;</span>;</span><br><span class="line"></span><br><span class="line">  <span class="built_in">print</span>(str1);</span><br><span class="line">  <span class="built_in">print</span>(str2);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>不换行（打印）：</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">PS</span> C:\Users\Admin\Desktop\dart_demo&gt; dart .\demo01.dart</span><br><span class="line">test string <span class="number">01</span></span><br><span class="line">test string <span class="number">02</span></span><br></pre></td></tr></table></figure></li>
<li><p>换行（示例）：三个单引号 // 三对双引号</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">void</span> main() &#123;</span><br><span class="line">  <span class="built_in">String</span> str1 = <span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">  Test String 01</span></span><br><span class="line"><span class="string">  Test String 02</span></span><br><span class="line"><span class="string">  &#x27;&#x27;&#x27;</span>;</span><br><span class="line"></span><br><span class="line">  <span class="built_in">String</span> str2 = <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">  Test String 03</span></span><br><span class="line"><span class="string">  Test String 04</span></span><br><span class="line"><span class="string">  &quot;&quot;&quot;</span>;</span><br><span class="line"></span><br><span class="line">  <span class="built_in">print</span>(str1);</span><br><span class="line">  <span class="built_in">print</span>(str2);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>换行（打印）：</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">PS</span> C:\Users\Admin\Desktop\dart_demo&gt; dart .\demo01.dart</span><br><span class="line">  Test String <span class="number">01</span></span><br><span class="line">  Test String <span class="number">02</span></span><br><span class="line"></span><br><span class="line">  Test String <span class="number">03</span></span><br><span class="line">  Test String <span class="number">04</span></span><br></pre></td></tr></table></figure>


</li>
</ul>
<h5 id="5-4-2-Dart-字符串拼接"><a href="#5-4-2-Dart-字符串拼接" class="headerlink" title="5.4.2 Dart 字符串拼接"></a>5.4.2 Dart 字符串拼接</h5><ul>
<li><p>将两个字符串拼接</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&#x27;<span class="subst">$str1</span> <span class="subst">$str2</span>&#x27;</span></span><br><span class="line"><span class="string">&quot;<span class="subst">$str1</span> <span class="subst">$str2</span>&quot;</span></span><br><span class="line"> str1 + str2</span><br></pre></td></tr></table></figure>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">void</span> main() &#123;</span><br><span class="line">  <span class="built_in">String</span> str1 = <span class="string">&#x27;Hello&#x27;</span>;</span><br><span class="line">  <span class="built_in">String</span> str2 = <span class="string">&#x27;Wrold&#x27;</span>;</span><br><span class="line"></span><br><span class="line">  <span class="built_in">print</span>(str1 + <span class="string">&#x27; &#x27;</span> + str2);</span><br><span class="line">  <span class="built_in">print</span>(<span class="string">&#x27;<span class="subst">$str1</span> <span class="subst">$str2</span>&#x27;</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>打印结果：</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">PS</span> C:\Users\Admin\Desktop\dart_demo&gt; dart .\demo01.dart</span><br><span class="line">Hello Wrold</span><br><span class="line">Hello Wrold</span><br></pre></td></tr></table></figure>




</li>
</ul>
<h4 id="5-5-Dart-数值计算"><a href="#5-5-Dart-数值计算" class="headerlink" title="5.5 Dart 数值计算"></a>5.5 Dart 数值计算</h4><figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">void</span> main() &#123;</span><br><span class="line">  <span class="built_in">int</span> a = <span class="number">12</span>;</span><br><span class="line">  <span class="built_in">double</span> b = <span class="number">24.0</span>;</span><br><span class="line">  <span class="built_in">double</span> c = <span class="number">48</span>;</span><br><span class="line"></span><br><span class="line">  <span class="built_in">print</span>(a);</span><br><span class="line">  <span class="built_in">print</span>(b);</span><br><span class="line">  <span class="built_in">print</span>(c);</span><br><span class="line"></span><br><span class="line">  <span class="built_in">print</span>(<span class="string">&#x27;-------&#x27;</span>);</span><br><span class="line"></span><br><span class="line">  <span class="keyword">var</span> d = a + c;</span><br><span class="line">  <span class="keyword">var</span> e = c - a;</span><br><span class="line">  <span class="keyword">var</span> f = a * b;</span><br><span class="line">  <span class="keyword">var</span> g = c / a;</span><br><span class="line">  <span class="keyword">var</span> h = b % a;</span><br><span class="line"></span><br><span class="line">  <span class="built_in">print</span>(d);</span><br><span class="line">  <span class="built_in">print</span>(e);</span><br><span class="line">  <span class="built_in">print</span>(f);</span><br><span class="line">  <span class="built_in">print</span>(g);</span><br><span class="line">  <span class="built_in">print</span>(h);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">PS</span> C:\Users\Admin\Desktop\dart_demo&gt; dart .\demo01.dart</span><br><span class="line"><span class="number">12</span></span><br><span class="line"><span class="number">24.0</span>   </span><br><span class="line"><span class="number">48.0</span>   </span><br><span class="line">-------</span><br><span class="line"><span class="number">60.0</span>   </span><br><span class="line"><span class="number">36.0</span></span><br><span class="line"><span class="number">288.0</span></span><br><span class="line"><span class="number">4.0</span></span><br><span class="line"><span class="number">0.0</span></span><br></pre></td></tr></table></figure>




<h4 id="5-6-Dart-布尔类型"><a href="#5-6-Dart-布尔类型" class="headerlink" title="5.6 Dart 布尔类型"></a>5.6 Dart 布尔类型</h4><figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">void</span> main() &#123;</span><br><span class="line">  <span class="built_in">int</span> a = <span class="number">12</span>;</span><br><span class="line">  <span class="built_in">int</span> b = <span class="number">12</span>;</span><br><span class="line">  <span class="keyword">if</span> (a == b) &#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">&#x27;a = b&#x27;</span>);</span><br><span class="line">  &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">&#x27;a != b&#x27;</span>);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="built_in">bool</span> c = <span class="keyword">true</span>;</span><br><span class="line">  <span class="built_in">bool</span> d = <span class="keyword">false</span>;</span><br><span class="line">  <span class="keyword">if</span> (c == d) &#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">&#x27;c = d&#x27;</span>);</span><br><span class="line">  &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">&#x27;c != d&#x27;</span>);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">PS</span> C:\Users\Admin\Desktop\dart_demo&gt; dart .\demo01.dart</span><br><span class="line">a = b</span><br><span class="line">c != d</span><br></pre></td></tr></table></figure>




<h4 id="5-7-List-集合类型"><a href="#5-7-List-集合类型" class="headerlink" title="5.7 List 集合类型"></a>5.7 List 集合类型</h4><ul>
<li><p>不指定类型</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">void</span> main() &#123;</span><br><span class="line">  <span class="keyword">var</span> list1 = [<span class="string">&quot;FHang&quot;</span>, <span class="number">24</span>, <span class="keyword">true</span>];</span><br><span class="line">  <span class="built_in">print</span>(<span class="string">&quot;list1:&quot;</span>);</span><br><span class="line">  <span class="built_in">print</span>(list1);</span><br><span class="line">  <span class="built_in">print</span>(<span class="string">&quot;--------&quot;</span>);</span><br><span class="line"></span><br><span class="line">  <span class="built_in">print</span>(<span class="string">&quot;list frist:&quot;</span>);</span><br><span class="line">  <span class="built_in">print</span>(list1.first);</span><br><span class="line">  <span class="built_in">print</span>(list1[<span class="number">0</span>]);</span><br><span class="line">  <span class="built_in">print</span>(<span class="string">&quot;--------&quot;</span>);</span><br><span class="line"></span><br><span class="line">  <span class="built_in">print</span>(<span class="string">&quot;list second:&quot;</span>);</span><br><span class="line">  <span class="built_in">print</span>(list1[<span class="number">1</span>]);</span><br><span class="line">  <span class="built_in">print</span>(<span class="string">&quot;--------&quot;</span>);</span><br><span class="line"></span><br><span class="line">  <span class="built_in">print</span>(<span class="string">&quot;list last:&quot;</span>);</span><br><span class="line">  <span class="built_in">print</span>(list1.last);</span><br><span class="line">  <span class="built_in">print</span>(list1[<span class="number">2</span>]);</span><br><span class="line">  <span class="built_in">print</span>(<span class="string">&quot;--------&quot;</span>);</span><br><span class="line"></span><br><span class="line">  <span class="built_in">print</span>(<span class="string">&quot;list length:&quot;</span>);</span><br><span class="line">  <span class="built_in">print</span>(list1.length);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">PS</span> C:\Users\Admin\Desktop\dart_demo&gt; dart .\demo01.dart</span><br><span class="line">list1:</span><br><span class="line">[<span class="type">FHang</span>, <span class="number">24</span>, <span class="type">true</span>]</span><br><span class="line">--------</span><br><span class="line">list frist:      </span><br><span class="line">FHang</span><br><span class="line">FHang</span><br><span class="line">--------</span><br><span class="line">list second:</span><br><span class="line"><span class="number">24</span></span><br><span class="line">--------</span><br><span class="line">list last:</span><br><span class="line">true</span><br><span class="line">true</span><br><span class="line">--------</span><br><span class="line">list length:</span><br><span class="line"><span class="number">3</span></span><br></pre></td></tr></table></figure></li>
<li><p>指定类型</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">void</span> main() &#123;</span><br><span class="line">  <span class="keyword">var</span> list1 = &lt;<span class="built_in">String</span>&gt;[<span class="string">&quot;Fang&quot;</span>, <span class="string">&quot;Hang&quot;</span>];</span><br><span class="line">  <span class="built_in">print</span>(list1.first);</span><br><span class="line">  <span class="built_in">print</span>(list1.last);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">PS</span> C:\Users\Admin\Desktop\dart_demo&gt; dart .\demo01.dart</span><br><span class="line">Fang</span><br><span class="line">Hang</span><br></pre></td></tr></table></figure></li>
<li><p>添加/删除数据到集合</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">void</span> main() &#123;</span><br><span class="line">  <span class="keyword">var</span> list1 = [];</span><br><span class="line">  <span class="built_in">print</span>(list1.length);</span><br><span class="line">  <span class="built_in">print</span>(<span class="string">&quot;--------&quot;</span>);</span><br><span class="line"></span><br><span class="line">  <span class="comment">//添加</span></span><br><span class="line">  list1.add(<span class="string">&quot;Fang&quot;</span>);</span><br><span class="line">  list1.add(<span class="string">&quot;Hang&quot;</span>);</span><br><span class="line">  list1.add(<span class="number">24</span>);</span><br><span class="line">  <span class="built_in">print</span>(list1);</span><br><span class="line">  <span class="built_in">print</span>(list1.length);</span><br><span class="line">  <span class="built_in">print</span>(<span class="string">&quot;--------&quot;</span>);</span><br><span class="line"></span><br><span class="line">  <span class="comment">//删除</span></span><br><span class="line">  list1.removeAt(<span class="number">1</span>);</span><br><span class="line">  <span class="built_in">print</span>(list1);</span><br><span class="line">  <span class="built_in">print</span>(list1.length);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">PS</span> C:\Users\Admin\Desktop\dart_demo&gt; dart .\demo01.dart</span><br><span class="line"><span class="number">0</span></span><br><span class="line">--------        </span><br><span class="line">[<span class="type">Fang</span>, <span class="type">Hang</span>, <span class="number">24</span>]</span><br><span class="line"><span class="number">3</span></span><br><span class="line">--------        </span><br><span class="line">[<span class="type">Fang</span>, <span class="number">24</span>]</span><br><span class="line"><span class="number">2</span></span><br></pre></td></tr></table></figure></li>
<li><p>通过List.filled 来创建固定大小的集合</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">void</span> main() &#123;</span><br><span class="line">  <span class="comment">// 不指定类型</span></span><br><span class="line">  <span class="keyword">var</span> list1 = <span class="built_in">List</span>.filled(<span class="number">2</span>, <span class="string">&quot;&quot;</span>);</span><br><span class="line">  <span class="comment">// 指定类型</span></span><br><span class="line">  <span class="comment">// var list2 = List&lt;String&gt;.filled(2, &quot;&quot;);</span></span><br><span class="line">  <span class="built_in">print</span>(list1.length);</span><br><span class="line">  <span class="built_in">print</span>(list1);</span><br><span class="line"></span><br><span class="line">  list1[<span class="number">0</span>] = <span class="string">&quot;Fang&quot;</span>;</span><br><span class="line">  list1[<span class="number">1</span>] = <span class="string">&quot;hang&quot;</span>;</span><br><span class="line">  <span class="built_in">print</span>(list1);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">PS</span> C:\Users\Admin\Desktop\dart_demo&gt; dart .\demo01.dart</span><br><span class="line"><span class="number">2</span></span><br><span class="line">[, ]        </span><br><span class="line">[<span class="type">Fang</span>, <span class="type">hang</span>]</span><br></pre></td></tr></table></figure>




</li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">FHang</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://fhangh.gitee.io/article/5888643d.html">https://fhangh.gitee.io/article/5888643d.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://fhangh.gitee.io" target="_blank">Element</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/fhangh/tags/Dart/">Dart</a></div><div class="post_share"><div class="social-share" data-image="https://cdn.jsdelivr.net/gh/FHangH/FHangBlogCDN/Post_Img_mini/postImg_16.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/fhangh/article/5dfd4070.html"><img class="prev-cover" data-lazy-src="https://cdn.jsdelivr.net/gh/FHangH/FHangBlogCDN/Post_Img_mini/postImg_17.jpg" onerror="onerror=null;src='/fhangh/img/404.jpg'"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">C++_职工管理系统</div></div></a></div><div class="next-post pull-right"><a href="/fhangh/article/90395389.html"><img class="next-cover" data-lazy-src="https://cdn.jsdelivr.net/gh/FHangH/FHangBlogCDN/Post_Img_mini/postImg_15.jpg" onerror="onerror=null;src='/fhangh/img/404.jpg'"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Flutter基础</div></div></a></div></nav></div><div class="aside_content" id="aside_content"><div class="card-widget card-info"><div class="card-content"><div class="card-info-avatar is-center"><img class="avatar-img" data-lazy-src="/fhangh/img/fh.png" onerror="this.onerror=null;this.src='/fhangh/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">FHang</div><div class="author-info__description"></div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/fhangh/archives/"><div class="headline">文章</div><div class="length-num">26</div></a></div><div class="card-info-data-item is-center"><a href="/fhangh/tags/"><div class="headline">标签</div><div class="length-num">10</div></a></div><div class="card-info-data-item is-center"><a href="/fhangh/categories/"><div class="headline">分类</div><div class="length-num">4</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/FHangH"><i class="fab fa-github"></i><span>Link To</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/FHangH" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:752972182@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div></div><div class="card-widget card-announcement"><div class="card-content"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">个人学习笔记</div></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="card-content"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Dart"><span class="toc-number">1.</span> <span class="toc-text">Dart</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-Dart-%E5%AE%89%E8%A3%85"><span class="toc-number">1.0.1.</span> <span class="toc-text">1. Dart 安装</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-Dart-%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE"><span class="toc-number">1.0.2.</span> <span class="toc-text">2. Dart 环境配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-Dart-%E9%A1%B9%E7%9B%AE%E6%96%87%E4%BB%B6"><span class="toc-number">1.0.3.</span> <span class="toc-text">3. Dart 项目文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-Dart-%E5%9F%BA%E6%9C%AC%E8%AF%AD%E6%B3%95"><span class="toc-number">1.0.4.</span> <span class="toc-text">5. Dart 基本语法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#5-1-Dart-%E5%8F%98%E9%87%8F%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.0.4.1.</span> <span class="toc-text">5.1 Dart 变量类型</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-2-Dart-%E5%B8%B8%E9%87%8F"><span class="toc-number">1.0.4.2.</span> <span class="toc-text">5.2 Dart 常量</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-3-Dart-%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.0.4.3.</span> <span class="toc-text">5.3 Dart 数据类型</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-4-Dart-%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="toc-number">1.0.4.4.</span> <span class="toc-text">5.4 Dart 字符串</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#5-4-1-Dart-%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%AE%9A%E4%B9%89"><span class="toc-number">1.0.4.4.1.</span> <span class="toc-text">5.4.1 Dart 字符串定义</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#5-4-2-Dart-%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%8B%BC%E6%8E%A5"><span class="toc-number">1.0.4.4.2.</span> <span class="toc-text">5.4.2 Dart 字符串拼接</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-5-Dart-%E6%95%B0%E5%80%BC%E8%AE%A1%E7%AE%97"><span class="toc-number">1.0.4.5.</span> <span class="toc-text">5.5 Dart 数值计算</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-6-Dart-%E5%B8%83%E5%B0%94%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.0.4.6.</span> <span class="toc-text">5.6 Dart 布尔类型</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-7-List-%E9%9B%86%E5%90%88%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.0.4.7.</span> <span class="toc-text">5.7 List 集合类型</span></a></li></ol></li></ol></li></ol></li></ol></div></div></div><div class="card-widget card-recent-post"><div class="card-content"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/fhangh/article/3fadb38f.html" title="UE4联网和多人游戏"><img data-lazy-src="https://cdn.jsdelivr.net/gh/FHangH/FHangBlogCDN/Post_Img_mini/postImg_27.jpg" onerror="this.onerror=null;this.src='/fhangh/img/404.jpg'" alt="UE4联网和多人游戏"/></a><div class="content"><a class="title" href="/fhangh/article/3fadb38f.html" title="UE4联网和多人游戏">UE4联网和多人游戏</a><time datetime="2022-05-26T14:04:45.432Z" title="发表于 2022-05-26 22:04:45">2022-05-26</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/fhangh/article/7dd18469.html" title="UE4 RPC"><img data-lazy-src="https://cdn.jsdelivr.net/gh/FHangH/FHangBlogCDN/Post_Img_mini/postImg_26.jpg" onerror="this.onerror=null;this.src='/fhangh/img/404.jpg'" alt="UE4 RPC"/></a><div class="content"><a class="title" href="/fhangh/article/7dd18469.html" title="UE4 RPC">UE4 RPC</a><time datetime="2022-05-19T04:30:00.826Z" title="发表于 2022-05-19 12:30:00">2022-05-19</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/fhangh/article/cb9854b2.html" title="UE4 MySQL插件使用"><img data-lazy-src="https://cdn.jsdelivr.net/gh/FHangH/FHangBlogCDN/Post_Img_mini/postImg_25.jpg" onerror="this.onerror=null;this.src='/fhangh/img/404.jpg'" alt="UE4 MySQL插件使用"/></a><div class="content"><a class="title" href="/fhangh/article/cb9854b2.html" title="UE4 MySQL插件使用">UE4 MySQL插件使用</a><time datetime="2022-03-27T06:49:30.840Z" title="发表于 2022-03-27 14:49:30">2022-03-27</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/fhangh/article/605bd1ac.html" title="UE4 MySQL插件开发"><img data-lazy-src="https://cdn.jsdelivr.net/gh/FHangH/FHangBlogCDN/Post_Img_mini/postImg_24.jpg" onerror="this.onerror=null;this.src='/fhangh/img/404.jpg'" alt="UE4 MySQL插件开发"/></a><div class="content"><a class="title" href="/fhangh/article/605bd1ac.html" title="UE4 MySQL插件开发">UE4 MySQL插件开发</a><time datetime="2022-03-26T07:56:25.807Z" title="发表于 2022-03-26 15:56:25">2022-03-26</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/fhangh/article/f7ede91d.html" title="Java基础"><img data-lazy-src="https://cdn.jsdelivr.net/gh/FHangH/FHangBlogCDN/Post_Img_mini/postImg_19.jpg" onerror="this.onerror=null;this.src='/fhangh/img/404.jpg'" alt="Java基础"/></a><div class="content"><a class="title" href="/fhangh/article/f7ede91d.html" title="Java基础">Java基础</a><time datetime="2021-12-12T07:47:44.788Z" title="发表于 2021-12-12 15:47:44">2021-12-12</time></div></div></div></div></div></div></div></main><footer id="footer" style="background-image: url(https://cdn.jsdelivr.net/gh/FHangH/FHangBlogCDN/Post_Img/postImg_16.jpg)"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By FHang</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"><div id="local-hits"></div><div id="local-stats"><div class="local-search-stats__hr" id="hr"><span>由</span> <a target="_blank" rel="noopener" href="https://github.com/wzpan/hexo-generator-search" style="color:#49B1F5;">hexo-generator-search</a>
 <span>提供支持</span></div></div></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/fhangh/js/utils.js"></script><script src="/fhangh/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="/fhangh/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> {preloader.endLoading()})</script><div class="js-pjax"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="true"></script></div></body></html>